package java8.lambda.demo02;

import java8.lambda.demo01.AbstractAppleBeforeTest;
import java8.lambda.demo01.Apple;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.List;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

/**
 * @author ChangLiang
 * @date 2020/4/22
 */
public class AppTest extends AbstractAppleBeforeTest {

    @Test
    @DisplayName("test filter")
    public void test(){
        List<Apple> apple = AppleFilter.findApple(list, new GreenAnd150WeightPredicate());
        assertThat(apple.size()).isEqualTo(1);
    }


    @Test
    @DisplayName("test filter using lambda")
    public void test2(){
        List<Apple> apple = AppleFilter.findApple(list, apple1 -> apple1.getColor().equals("green") && apple1.getWeight() > 150);
        assertThat(apple.size()).isEqualTo(1);

        List<Apple> yellow = AppleFilter.findApple(list, apple1 -> apple1.getColor().equals("yellow") && apple1.getWeight() < 150);
        assertThat(yellow.size()).isEqualTo(1);
    }
}
